home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / utility3 / wtj008.zip / FAULT.ZIP / HANDLER.ASM < prev    next >
Assembly Source File  |  1992-05-13  |  2KB  |  70 lines

  1. ;
  2. ; HANDLER.ASM
  3. ;
  4.  
  5.     .xlist
  6.     ?PLM=1
  7.     ?WIN=1
  8.     include cmacros.inc
  9.     include toolhelp.inc
  10.     .list
  11.  
  12.  
  13. ;; External data.
  14. externFP <Throw>                ;From Kernel
  15. externFP <TerminateApp>         ;From ToolHelp
  16.  
  17. externW  <_fTrapGPFault>
  18. externFP <_pCB>
  19.  
  20. createSeg HANDLER_TEXT, HANDLER_TEXT, BYTE, PUBLIC, CODE
  21. sBegin    HANDLER_TEXT
  22. assumes   CS,HANDLER_TEXT
  23. assumes   DS,_DATA
  24.  
  25.  
  26. ;
  27. ; FaultHandler
  28. ;
  29. ; Purpose:
  30. ;  Interrupt handling function called from ToolHelp when it detects
  31. ;  an interrupt.  If the error was caused by our application AND we
  32. ;  want to trap it, then we use Throw to return control to the function.
  33. ;  If we do not want the fault, then we just pass it to the next interrupt
  34. ;  handler.
  35. ;
  36.  
  37. cProc   FaultHandler, <PUBLIC,FAR>
  38. cBegin  nogen
  39.  
  40.         mov     ds,ax               ;Make sure we can reference our data.
  41.  
  42.         ;If we do not want to process interrupts, get out ASAP.
  43.         mov     ax,_fTrapGPFault    ;Do we want to process interrupts?
  44.         or      ax,ax
  45.         jnz     FHContinue          ;Yes, continue.
  46.  
  47. FHExit:
  48.         retf                        ;Pass the interrupt to the next handler.
  49.  
  50. FHContinue:
  51.         mov     ax,bp               ;Load the interrupt number without
  52.         mov     bp,sp               ;changing the BP register and without
  53.         mov     bx,[bp+06]          ;using the stack with a push an pop.
  54.         mov     bp,ax
  55.  
  56.         ;Leave if there was a fatal stack fault.
  57.         test    bx,08000h           ;Check high bit
  58.         jnz     FHExit
  59.  
  60.         ;Check for a GP fault.
  61.         cmp     bx,13
  62.         jne     FHExit
  63.  
  64.         ;We GP Faulted, return to the faulting function.
  65.         ccall   Throw,<_pCB, 1>
  66.  
  67. cEnd    nogen
  68. sEnd    HANDLER_TEXT
  69.         END
  70.